<script setup lang="ts">
import {ref} from "vue";
import myAxios from "../../api/myAxios";
import {Toast} from "vant";

const loginAccount = ref('')
const loginPassword= ref('')
const checkPassword= ref('')
const showText = ref('哇,又新入驻了一位帅哥(美女)哦,欢迎欢迎~~~')

const onSubmit = () => {
  console.log('submit', loginAccount.value, loginPassword.value, checkPassword.value)
  myAxios.post('/user/register', {
    loginAccount: loginAccount.value,
    loginPassword: loginPassword.value,
    checkPassword: checkPassword.value,
  }).then(res => {
    if (res.code === 0 && res.data) {
      Toast.success('注册成功');
      // 跳转到登录页面
      window.location.href = '/user/login';
    } else {
      Toast.fail('注册失败'+(res.description ? `，${res.description}` : ''));
   }
  })
}

</script>

<template>

  <van-notice-bar scrollable :text="showText" />
  <div id="header"> <img src="../../assets/唐老鸭-register.jpg"></div>

  <van-form @submit="onSubmit">
    <van-cell-group inset>
      <van-field
          v-model="loginAccount"
          name="loginName"
          label="账号"
          placeholder="请输入账号"
          :rules="[{ required: true, message: '请填写账号' }]"
      />
      <van-field
          v-model="loginPassword"
          type="password"
          name="loginPassword"
          label="密码"
          placeholder="请输入密码"
          :rules="[{ required: true, message: '请填写密码' }]"
      />
      <van-field
          v-model="checkPassword"
          type="password"
          name="checkPassword"
          label="确认密码"
          placeholder="请输入确认密码"
          :rules="[{ required: true, message: '请再次填写确认密码' }]"
      />
    </van-cell-group>
    <div style="margin: 16px;">
      <van-button round block type="primary" native-type="submit">
        注册
      </van-button>
    </div>
  </van-form>

</template>

<style scoped>
#header{
  text-align: center;
}
#header img{
  height: 330px;
  width: 330px;
}
</style>
<!--
  "checkPassword": "",
  "loginAccount": "",
  "loginPassword": ""-->
